/**
 * 
 */
package com.syncshot.androidapp.util;

import java.util.HashMap;
import java.util.Map;

import com.syncshot.androidapp.Constant;
import com.syncshot.androidapp.helper.WSHelper;
import com.syncshot.androidapp.helper.WSHelper.Call;
import com.syncshot.androidapp.helper.WSHelper.Call.CallType;
import com.syncshot.androidapp.model.Event;
import com.syncshot.androidapp.model.EventCreation;
import com.syncshot.androidapp.model.EventSubscription;
import com.syncshot.androidapp.model.Me;
import com.syncshot.androidapp.model.Picture;
import com.syncshot.androidapp.model.PictureList;
import com.syncshot.androidapp.model.ServerTime;
import com.syncshot.androidapp.model.User;

/**
 * @author Stan
 * 
 */
public class WSUtil {
    /** Used locally to tag Logs */
    @SuppressWarnings("unused")
    private static final String TAG = "WSUtil";

    public static String generateURLUploadPicture(String eventId, String lon, String lat, String userId) {
       return Constant.WS_UPLOAD_PICTURE.replace("{eventid}", eventId).replace("{longitude}", lon).replace("{latitude}", lat).replace("{nickname}", userId);
    }
    

    public static Call generateCallPictureList(String eventId) {
        String url = Constant.WS_PICTURE_LIST.replace("{eventid}", eventId);
        return new Call(CallType.GET, url, Picture[].class);
    }

    public static Call generateCallNewEvent(Event event) {
        String url = Constant.WS_NEW_EVENT;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(WSHelper.KEY_BODY, Parser.getInstance().serialize(event));
        return new Call(CallType.POST, url, map, EventCreation.class);
    }

    public static Call generateCallUpdateUserLocation(Me me) {
        String url = Constant.WS_USER_LOCATION;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(WSHelper.KEY_BODY, Parser.getInstance().serialize(me));
        return new Call(CallType.POST, url, map, ServerTime.class);
    }
    
    public static String generateUrlgetPicture(int pictureId, boolean askForThumbnail) {
        String url = Constant.WS_GET_PICTURE;
        url = url.replace("{pictureid}", String.valueOf(pictureId));
        url = url.replace("{thumbnail}", String.valueOf(askForThumbnail));
        return url;
    }
    
    public static Call generateCallUserList(String eventId) {
        String url = Constant.WS_USER_LIST.replace("{eventid}", eventId);
        return new Call(CallType.GET, url, User[].class);
    }
    
    public static Call generateCallUserList(String lat, String lon) {
        String url = Constant.WS_USER_LIST_LOCATION.replace("{longitude}", lon).replace("{latitude}", lat);
        return new Call(CallType.GET, url, User[].class);
    }
    
    public static Call generateCallEventList(String lat, String lon) {
        String url = Constant.WS_EVENT_LIST.replace("{longitude}", lon).replace("{latitude}", lat);
        return new Call(CallType.GET, url, Event[].class);
    }
    
    public static Call generateCallEvent(String eventid) {
        String url = Constant.WS_EVENT_INFO.replace("{eventid}", eventid);
        return new Call(CallType.GET, url, Event.class);
    }
    
    
    
    public static Call generateCallTakeShot(String eventId) {
        String url = Constant.WS_TAKE_SHOT.replace("{eventid}", eventId);
        return new Call(CallType.POST, url, null);
    }
    
    public static Call generateCallSubscribeToEvent(String eventId, String username) {
        String url = Constant.WS_SUBSCRIBE;
        EventSubscription eventSubscription = new EventSubscription();
        eventSubscription.setNickName(username);
        eventSubscription.setEvenetId(Integer.parseInt(eventId));
        Map<String, Object> wmap = new HashMap<String, Object>();
        wmap.put(WSHelper.KEY_BODY, Parser.getInstance().serialize(eventSubscription));

        return new Call(CallType.POST, url, wmap, null);
    }
    
    
}
